Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

400
Visualizações
Error when using test_client (Flask) - raise ValueError("unknown url type: %r" % self.full_url)

flask application code:

# main.py 
from flask import Flask, Response
app = Flask(__name__)


@app.route("/", methods=["POST"])
def post_example():
    return Response("aaa")

and this is my testing code:

# e2e.py
from main import app

test_client = app.test_client()


def test_flask_api_call():
    response = test_client.post("/", {"a": "b"})
    pass

I keep receiving:

raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: '://%7B%27a%27:%20%27b%27%7D/'
   
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The problem is on the post method call. You have to name your data arguments client.post("/", data={"a": "b"}), if it's not the case it is considered as a part of the URL.

urllib.parse.quote("/" + str({"a": "b"}))
# '/%7B%27a%27%3A%20%27b%27%7D'

Here is the test code rewritten to define a fixture for the client initialization. More info on testing flask application on the official doc.

import pytest

from main import app


@pytest.fixture(scope="module")
def client():
    with app.test_client() as client:
        yield client


def test_flask_api_call(client):
    response = client.post("/", data={"a": "b"})
    assert response.status_code == 200, f"Got bad status code {response.status_code}"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda